package com.iflytek.jobs.admin.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.iflytek.jobs.service.util.ApiAuthUtil;
import com.ruoyi.common.core.domain.AjaxResult;

import java.util.HashMap;
import java.util.Map;

import org.springframework.web.bind.annotation.GetMapping;


@RestController
@RequestMapping("/jobs/xfyun")
public class XfyunController {

    
    @GetMapping("/sign/spark/doc")
    public AjaxResult signature(){
        String appId = "00a1d5d4";// 控制台获取
        String secret = "ZjA3OGZlMjg3YmZhNjhiMGMxODY5YWFm";// 控制台获取
        // String uploadUrl = "https://chatdoc.xfyun.cn/openapi/v1/file/upload";
        // String chatUrl = "wss://chatdoc.xfyun.cn/openapi/chat?appId=xxx&timestamp=xxx&signature=xxxxxx";
        // String statusUrl = "https://chatdoc.xfyun.cn/openapi/v1/file/status";
        long ts = System.currentTimeMillis() / 1000;
        String timestamp = String.valueOf(ts);
        String signature = ApiAuthUtil.getSignature(appId, secret, ts);
        Map<String, String> map = new HashMap<>();
        map.put("appId", appId);
        map.put("timestamp", timestamp);
        map.put("signature", signature);
        return AjaxResult.success(map);
    }

    @GetMapping("/sign/avatar")
    public AjaxResult signByAvatar(){
        String reUrl = "";
        String url = "wss://avatar.cn-huadong-1.xf-yun.com/v1/interact";
        String appId = "3665ea17";
        String apiKey = "e50666f3510db9fe7d9e3622a7427ec0";
        String apiSecret = "YThlODQ1N2IyZjkwYTZjYzY0ZTJmZmRj";
        try {
            reUrl =ApiAuthUtil.getAuthUrl(url, apiKey, apiSecret);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Map<String, String> map = new HashMap<>();
        map.put("url", reUrl);
        map.put("appId", appId);
        return AjaxResult.success(map);
    }

    @GetMapping("/sign/deepseek")
    public AjaxResult signByDeepseek(){
        String reUrl = "";
        String url = "wss://maas-api.cn-huabei-1.xf-yun.com/v1.1/chat";
        String appId = "3665ea17";
        String apiKey = "9192002936dcc76a715cacd8beff4a89";
        String apiSecret = "NWE3Y2NjNmQwN2M1NjgxNjY3Y2FkM2Rl";
        try {
            reUrl =ApiAuthUtil.getAuthUrl(url, apiKey, apiSecret);
        } catch (Exception e) {
            e.printStackTrace();
            }
        Map<String, String> map = new HashMap<>();
        map.put("url", reUrl);
        map.put("appId", appId);
        return AjaxResult.success(map);
    }

    @GetMapping("/sign/sparkmax")
    public AjaxResult signBySparkMax(){
        String reUrl = "";
        String url = "wss://maas-api.cn-huabei-1.xf-yun.com/v1.1/chat";
        String appId = "a3090d6b";
        String apiKey = "da1a7017d25c98ab90a6238009dacc49";
        String apiSecret = "Nzc5Zjk3OWE2ODdmMmE5NDZhZTEwYjVj";
        String serviceId = "xsparkprox";
        String resourceId = "0";
        try {
            reUrl =ApiAuthUtil.getAuthUrl(url, apiKey, apiSecret);
        } catch (Exception e) {
            e.printStackTrace();
            }
        Map<String, String> map = new HashMap<>();
        map.put("url", reUrl);
        map.put("appId", appId);
        map.put("serviceId", serviceId);
        map.put("resourceId", resourceId);
        return AjaxResult.success(map);
    }

    @GetMapping("/sign/iat")
    public AjaxResult signByIat(){
        String reUrl = "";
        String url = "wss://iat-api.xfyun.cn/v2/iat";
        String appId = "00a1d5d4";
        String apiKey = "2b24bc32ffeaf737789c5d21bee05979";
        String apiSecret = "ZjA3OGZlMjg3YmZhNjhiMGMxODY5YWFm";
        try {
            reUrl =ApiAuthUtil.getAuthUrl(url, apiKey, apiSecret);
        } catch (Exception e) {
            e.printStackTrace();
            }
        Map<String, String> map = new HashMap<>();
        map.put("url", reUrl);
        map.put("appId", appId);
        return AjaxResult.success(map);
    }
   
    


}
